Vectors
The easiest way to manipulate vectors in Python is by using the Numpy module, you can import it with
import numpy as np
Make sure to do this every time you start a new Python interpreter or at the start of your code.
Writing vectors
The vector $\vec{a}= (2,1,0)$ can be written as
a = np.array([2, 1, 0])
Try it out
```Adding and subtracting vectors
Vectors can be added and subtracted like numbers in python using +
and -
.
For example:
a = np.array([2, 1, 0])
b = np.array([6, 0, 4])
add = a + b
subtract = a - b
Try it out
```Modulus of a vector
The modulus of a vector can be calculated with np.linalg.norm(v)
For example, the modulus product of $\vec{a}= (2,1,0)$ would be written as
a = np.array([2, 1, 0])
np.linalg.norm(a)
Try it out
```Dot product
Dot products can be easily computed with np.dot(u, v)
For example, the dot product of $\vec{a}= (2,1,0)$ and $\vec{a}= (6,0,4)$ would be written as
a = np.array([2, 1, 0])
b = np.array([6, 0, 4])
np.dot(a, b)
Try it out
```Cross product
Cross products can be easily computed with np.cross(u, v)
For example, the cross product of $\vec{a}= (2,1,0)$ and $\vec{a}= (6,0,4)$ would be written as
a = np.array([2, 1, 0])
b = np.array([6, 0, 4])
np.cross(a, b)